package com.patrick.open.api.core.utils;

/**
 * 字符串工具包
 *
 * @author gaopeng
 * @date 2019/10/22 09:02 AM
 */
public class StrGzp {

  /**
   * 首字母小写
   *
   * @param str 字符串
   * @return
   */
  public static String firstCharToLowerCase(String str) {
    char firstChar = str.charAt(0);
    if (firstChar >= 'A' && firstChar <= 'Z') {
      char[] arr = str.toCharArray();
      arr[0] = (char) (arr[0] + 32);
      return new String(arr);
    } else {
      return str;
    }
  }

  /**
   * 首字母大写
   *
   * @param str 字符串
   * @return
   */
  public static String firstCharToUpperCase(String str) {
    char firstChar = str.charAt(0);
    if (firstChar >= 'a' && firstChar <= 'z') {
      char[] arr = str.toCharArray();
      arr[0] = (char) (arr[0] - 32);
      return new String(arr);
    } else {
      return str;
    }
  }

  /**
   * 将null转换为空字符串
   *
   * @param s 待转换的字符串
   * @return 转换的结果
   */
  public static String null2Empty(String s) {
    if (s == null) {
      s = "";
    }
    return s;
  }
}
